<template>
  <div class="purcharse-container" v-if="stocks?.length">
    <div class="purchased-bar">
      <img src="../../assets/index/group.png" alt="" class="lock" />
      <img src="../../assets/purchased.png" alt="已购股票" class="purcharse-stock" />
      <div class="division-line"></div>
      <div class="stocks">{{ stocks }}</div>
      <div class="goto-look" @click.stop="gotoPurcharse">去查看</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue';
import { jumpByUrl } from '@/utils';
import useGetPurchased from '@/hooks/useGetPurchased';

const { list, getPurchasedList } = useGetPurchased('PurchasedBar.vue');
const stocks = computed(() => {
  const authList = list.value.filter(item => item.hasAuth);
  let result = '';
  const limitNum = 4;
  for (let index = 0; index < authList.length; index++) {
    const element = authList[index];
    result += `、${element.stockName}`;
    if (index >= limitNum || index + 1 === authList.length) {
      return result.slice(1);
    }
  }
});
const gotoPurcharse = () => {
  jumpByUrl({ name: 'purchased' });
};
onMounted(() => {
  getPurchasedList();
});
interface Emits {}
const emits = defineEmits<Emits>();
</script>

<style scoped lang="less">
.purcharse-container {
  box-sizing: border-box;
  width: 100%;
  height: 98px;
  padding: 16px 12px 2px;
  .purchased-bar {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    border-radius: 16px;
    background: var(--bg-color-1);
    .lock {
      width: 40px;
      height: 40px;
      margin-left: 20px;
    }
    .purcharse-stock {
      width: 110px;
      height: 26px;
      margin-left: 16px;
    }
    .division-line {
      width: 1px;
      height: 32px;
      opacity: 0.4;
      background: rgba(255, 49, 65, 1);
      margin-left: 16px;
    }
    .stocks {
      width: 326px;
      height: 40px;
      text-align: left;
      color: rgba(255, 36, 54, 1);
      font-family: PingFang SC;
      font-size: 28px;
      margin-left: 16px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .goto-look {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 148px;
      height: 56px;
      border-radius: 16px;
      border: 2px solid rgba(255, 62, 62, 1);
      box-sizing: border-box;
      background: var(--bg-color-2);
      color: rgba(233, 48, 48, 1);
      font-family: PingFang SC;
      font-size: 28px;
      margin-left: 16px;
      line-height: 28px;
    }
  }
}
</style>
